﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace cmdb.keede.entity.Migrations
{
    public partial class updateapplicationvirtualhost : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ApplicationHost");

            migrationBuilder.CreateTable(
                name: "ApplicationVirtualHost",
                columns: table => new
                {
                    ApplicationId = table.Column<int>(nullable: false),
                    VirtualHostId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ApplicationVirtualHost", x => new { x.ApplicationId, x.VirtualHostId });
                    table.ForeignKey(
                        name: "FK_ApplicationVirtualHost_ApplicationInfo_ApplicationId",
                        column: x => x.ApplicationId,
                        principalTable: "ApplicationInfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ApplicationVirtualHost_VirtualHostInfo_VirtualHostId",
                        column: x => x.VirtualHostId,
                        principalTable: "VirtualHostInfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationVirtualHost_VirtualHostId",
                table: "ApplicationVirtualHost",
                column: "VirtualHostId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ApplicationVirtualHost");

            migrationBuilder.CreateTable(
                name: "ApplicationHost",
                columns: table => new
                {
                    Id = table.Column<int>(unicode: false, maxLength: 50, nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    ApplicationId = table.Column<int>(nullable: false),
                    HostId = table.Column<int>(nullable: true),
                    Name = table.Column<string>(unicode: false, maxLength: 50, nullable: true),
                    Operator = table.Column<string>(unicode: false, maxLength: 50, nullable: true),
                    Status = table.Column<int>(unicode: false, maxLength: 10, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ApplicationHost", x => x.Id);
                    table.ForeignKey(
                        name: "FK_APPLICAT_REFERENCE_APPLICAT",
                        column: x => x.ApplicationId,
                        principalTable: "ApplicationInfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_APPLICAT_REFERENCE_VIRTUALH",
                        column: x => x.HostId,
                        principalTable: "VirtualHostInfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationHost_ApplicationId",
                table: "ApplicationHost",
                column: "ApplicationId");

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationHost_HostId",
                table: "ApplicationHost",
                column: "HostId");
        }
    }
}
